package com.fuluwa.domain.bank.model;

import com.fuluwa.domain.shared.AbstractIdMantainceDomainObject;
import com.fuluwa.infra.event.GlobalEvent;
import com.fuluwa.infra.event.GlobalEvent.EventType;

import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;

@Entity
@Table(name="b_earning_def", uniqueConstraints={@javax.persistence.UniqueConstraint(columnNames={"account_type", "event_type"})})
public class EarningDefine extends AbstractIdMantainceDomainObject
{

  @Column(name="event_type")
  @Enumerated(EnumType.STRING)
  private GlobalEvent.EventType eventType;

  @Column(name="account_type")
  @Enumerated(EnumType.STRING)
  private Account.AccountType accountType;
  private BigDecimal amount;

  private EarningDefine()
  {
  }

  public EarningDefine(GlobalEvent.EventType eventType, Account.AccountType accountType)
  {
    this.eventType = eventType;
    this.accountType = accountType;
  }

  public EarningDefine(GlobalEvent.EventType eventType, Account.AccountType accountType, BigDecimal amount) {
    this.eventType = eventType;
    this.accountType = accountType;
    this.amount = amount;
  }

  public int hashCode()
  {
    int prime = 31;
    int result = super.hashCode();
    result = 31 * result + (this.accountType == null ? 0 : this.accountType.hashCode());
    result = 31 * result + (this.eventType == null ? 0 : this.eventType.hashCode());
    return result;
  }

  public boolean equals(Object obj)
  {
    if (this == obj)
      return true;
    if (!super.equals(obj))
      return false;
    if (getClass() != obj.getClass())
      return false;
    EarningDefine other = (EarningDefine)obj;
    if (this.accountType != other.accountType) {
      return false;
    }
    return this.eventType == other.eventType;
  }

  public GlobalEvent.EventType getEventType()
  {
    return this.eventType;
  }

  public Account.AccountType getAccountType() {
    return this.accountType;
  }

  public BigDecimal getAmount() {
    return this.amount;
  }
}